<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery-3.1.1.js"/>"></script>

<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>住院办理</title>
<style type="text/css">
.cc_item{
	padding:10px;
	
}
</style>
</head>
<body>
<script type="text/javascript">
	$(function(){
		$('#cc_applysearch').searchbox({
		    searcher:function(value,name){
		    	if(name=="病人姓名"){
		    		$("#hospapplytab").datagrid({
			    		url:'tocc_queryhaname',
			    		queryParams: {
			    			haname: value
			    		}
			    	});
		    	}else{
		    		$("#hospapplytab").datagrid({
			    		url:'tocc_queryhmedicalid',
			    		queryParams: {
			    			hmedicalid: value
			    		}
			    	});
		    	}
		    	
		    }
		});
		$.extend($.fn.validatebox.defaults.rules, {
			Chackpho: {
		        validator: function(value){
		        	  var myreg =/^1[34578]\d{9}$/;
		        	  if( myreg.test(value)){    		  
		        		  return true;
		        	  }else{
		        		  return false;
		        	  }
		        	   
		        },
		        message: '电话号码有误！！'
		    }
		});
		var  shenpi_staffId = $("#tontyiStaffId").html();
		$("#cc_hpdoctorid").val(shenpi_staffId);
		$("#cc_addapply").linkbutton({
			onClick : function(index, row) {
				var rows = $("#hospapplytab").datagrid("getSelections");
				if(rows.length == 1){
					if(rows[0].hpremarks=='已办理'){
						$.messager.alert("提示", "该病人的申请已经通过，不能重复办理！");
					}else if(rows[0].hpremarks=='已取消'){
						$.messager.alert("提示", "该病人已经取消申请，不能办理业务！");
					}else{
						$('#patientwin').window({'title': "办理住院"});
						
						//初始化表单
						//pname hmed_id pname；
						$("#hmed_id").textbox("setText",rows[0].hmedicalid);
						$("#hmed_id").textbox("setValue",rows[0].hmedicalid);
						console.log(rows[0].haname);
						var pname=rows[0].haname;
						$("#pname").textbox("setText", pname);
						$("#pname").textbox("setValue", pname);
						$("#cc_applyid").val(rows[0].applyid);
						$("#department").combogrid("setText",rows[0].departmentName);
						$("#department").combogrid("setValue",rows[0].departmentNo);
						$("#hpdoctorid").val(shenpi_staffId);
						//alert(rows[0].hpsex);
						//$("#cc_psex").combobox("setText",rows[0].hpsex);
						//$("#cc_psex").combobox("setValue",rows[0].hpsex);
						$("#cc_psex").textbox("setText",rows[0].hpsex);
						$("#cc_psex").textbox("setValue",rows[0].hpsex);
						//alert($("#cc_applyid").textbox("value"));
						$("#hmed_id").textbox("readonly", true);
						$("#pname").textbox("readonly", true);
						$("#cc_psex").textbox("readonly", true);
						$('#patientwin').window("open");
					}
				}else{
					$.messager.alert("提示", "只能选择一条记录，您目前选择了" + rows.length + "条!");
				}
			}
		});
		$("#cc_applydel").linkbutton({onClick: function(){
			$.messager.confirm("提示", "确定要取消吗？", function(v){
				if(v){
					//获取所有选中的编号
					var rows = $("#hospapplytab").datagrid("getSelections");
					var doctorid= $("#cc_hpdoctorid").textbox("getValue");
					//将编号保存到数组中
					var arr = [];
					var cal_jg=false;
					for(var i = 0; i < rows.length; i ++){
						if(rows[i].hpremarks=='已办理'){
							cal_jg=true;
						}else if(rows[i].hpremarks=='已取消'){
							cal_jg=true;
						}else{
							cal_jg=false;
						}
						if(cal_jg==false){
							arr.push(rows[i].applyid);
						}
					}
					//用form提交
					$('<form>').form('submit', {
					    url:'delcchosp',
					    onSubmit: function(param){
					    	param.list=arr;
					    	param.hpdoctorid=doctorid;
					    },
					    success:function(data){
					    	
					    	var json = eval("(" + data + ")");
							$.messager.alert("提示", json.reason);
							$("#hospapplytab").datagrid("reload");
					    }
					});
				}
			});
		}});
		
		$("#cc_patientsave").linkbutton({
			onClick : function() {
				$('#cc_patient').form('submit', {
					onSubmit : function() {
						 //返回true提交表单，返回false则阻止表单提交
			             return $(this).form('validate');
					},
					success : function(data) {
						//JSON字符串两边需要添加小括号
						var json = eval("(" + data + ")");
						$.messager.alert("提示", json.reason);
						
						//关闭窗口
						$('#patientwin').window('close');
						
						//重新加载数据
						$("#hospapplytab").datagrid("reload");
						$(this).form("clear");
					}
				});
			}
		});
		$("#cc_patientcancel").linkbutton({
			onClick : function() {
				$('#cc_patient').form("clear");
				$("#patientwin").window("close");
			}
		});
		$("#cc_showAllapply").linkbutton({
			onClick:function(){
				$("#hospapplytab").datagrid({
					 url: 'tocc_queryAllapply'
				});
			}
		});
		$("#cc_applyref").linkbutton({
			onClick:function(){
				$("#hospapplytab").datagrid({
					 url: 'tocc_queryAllhosp'
				});
			}
		});
		$("#department").combogrid({
			onChange:function(newValue,oldValue){
				var deptid= $("#department").combogrid("getValue");
				/* $.getJSON("tocc_queryByStaff", {"deptid": deptid}, function(data){
					$("#padoctorid").combogrid("setValue", data.staffNo);
					$("#padoctorid").combogrid("setText", data.staffName);
				}); */
				$("#padoctor").combogrid({
		    		url:'tocc_queryByStaff',
		    		queryParams: {
		    			deptid: deptid
		    		}
		    	});
			}
		});
	});
	function cc_hospapprowStlye(index,row){
		//alert(new Date());
		var date = new Date();
	    var seperator1 = "/";
	    var month = date.getMonth() + 1;
	    var strDate = date.getDate();
	    if (month >= 1 && month <= 9) {
	        month = "0" + month;
	    }
	    if (strDate >= 0 && strDate <= 9) {
	        strDate = "0" + strDate;
	    }
	    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
	    if (row.adate==currentdate){
			return 'background-color:#CCFF99;color:red;';
			
		}
	}
</script>
	<div style="display: none">
		<input id="cc_hpdoctorid"  name="hpdoctorid" class="easyui-textbox">
	</div>
	<table id="hospapplytab" class="easyui-datagrid"
		data-options="
				fitColumns:true,
				fit:true,
				rownumbers: true,
				striped:true,
			    url: 'tocc_queryAllhosp',
				border:false ,
				pagination:true,
				toolbar: '#cc_applybtn',
				pageSize: 16,
				pageList:[16,32,64,128],
				rowStyler: cc_hospapprowStlye
			">
		<thead>
			<tr>
				<th data-options="field:'applyid', width:'5%',checkbox:true">ID</th>
				<th data-options="field:'hmedicalid', width:'15%'">医疗卡编号</th>
				<th data-options="field:'haname', width:'12%'">姓名</th>
				<th data-options="field:'hpsex', width:'10%'">性别</th>
				<th data-options="field:'departmentNo', width:'15%'">科室编号</th>
				<th data-options="field:'departmentName', width:'10%'">科室</th>
				<th data-options="field:'hpremarks', width:'11%'">状态</th>
				<th data-options="field:'adate', width:'25%'">申请时间</th>
				
			</tr>
		</thead>
	</table>
	<div id="cc_applybtn">
	<a id="cc_showAllapply" class="easyui-linkbutton"
			data-options="iconCls:'icon-suoyou',plain:true">查看所有</a>
		<a id="cc_addapply" class="easyui-linkbutton"
			data-options="iconCls:'icon-add',plain:true">办理住院</a> <a id="cc_applydel"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-remove',plain:true">取消申请</a> <a id="cc_applyref"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-reload',plain:true">刷新</a> <input
			id="cc_applysearch" class="easyui-searchbox"
			data-options="menu:'#cc_applyee',width:220,prompt:'请输入你要查找的内容'">
	</div>
	<div id="cc_applyee" style=" width:90px">
		<div date-options="name:'name'">医疗卡编号</div>
		<div date-options="name:'name'">病人姓名</div>
	</div>
	<div>
		<div id="patientwin" class="easyui-window"
			style="padding:10px;line-height: 150%; background: rgb(236,243,255);"
			data-options="
			iconCls:'icon-banliyewu',
		     width: 370,
		     height: 370,
		      modal:true,
		     closed: true,
		     title:'住院办理'
			">
			
				<form id="cc_patient" action="addccpatient" method="post">
					<div style="display: none">
						<input id="hpdoctorid" name="hpdoctorid">
						<input  id="cc_applyid" name="applyid">
					</div>
					<div class="cc_item">
						<input id="hmed_id" name="icid" class="easyui-textbox"
							data-options="label: '医疗卡编号:',labelAlign:'right', width: 260">
					</div>
					<div class="cc_item">
						<input id="pname" name="pname" class="easyui-textbox"
							data-options="label: '患者姓名:', labelAlign:'right', width: 260">
					</div>
					<div class="cc_item">
						
					     <input id="cc_psex" name="psex" class="easyui-textbox" data-options="
					          labelAlign:'right', width: 260,
					          label:'性别:'
					     ">
					</div>
					<div class="cc_item">
						<input id="cc_pmoney" name="pmoney" class="easyui-numberbox"
							data-options="label: '预交金额:', labelAlign:'right', 
							width: 260">
					</div>
					<div class="cc_item">
						<input id="tname" name="tname" class="easyui-textbox"
							data-options="label: '联系人:', labelAlign:'right',
							required: true,
     						missingMessage: '联系人不能为空',
							width: 260">
					</div>
					<div class="cc_item">
						<input id="cc-tel" name="tel" class="easyui-numberbox"
							data-options="label: '联系电话:', labelAlign:'right', 
							required: true,
     						missingMessage: '联系电话不能为空',
     						 validType: ['Chackpho'],
							width: 260">
					</div>
					
					<div class="cc_item">
						<input id="pweight" name="pweight" class="easyui-numberbox"
							data-options="label: '体重(kg):', labelAlign:'right', 
							required: true,
     						missingMessage: '体重不能为空',
							width: 260">
					</div>
					<div class="cc_item">
						<select id="department" name="pofficesid" name="pofficesid" class="easyui-combogrid" data-options="
							labelAlign:'right', width: 260,
							label:'科室:',
							panelHeight: 'auto',
							required: true,
     						missingMessage: '科室不能为空',
							panelWidth: '303',
							url: 'queryTbdepartment',
							pagination:true,
							pageSize: 6,
							pageList:[6,12,24,48],
							idField: 'departmentNo',
							textField: 'departmentName',
							columns: [[
								{field: 'departmentNo', title: '科室编号', width: 120},
								{field: 'departmentName', title: '科室名称', width: 180},
							]]
						"></select>
					</div>
					<div class="cc_item">
						<select id="padoctor" name="padoctorid" class="easyui-combogrid" data-options="
							labelAlign:'right', width: 260,
							label:'主治医生:',
							panelHeight: 'auto',
							required: true,
     						missingMessage: '主治医生不能为空',
							panelWidth: '233',
							url: 'queryTbstaff',
							idField: 'staffNo',
							textField: 'staffName',
							columns: [[
								{field: 'staffNo', title: '医生编号', width: 80},
								{field: 'staffName', title: '医生姓名', width: 80},
								{field: 'departmentName', title: '科室', width: 60},
							
							]]
						"></select>
					</div>
					<div style="margin-left:20%;padding-top:4px">
						<a id="cc_patientsave"  class="easyui-linkbutton" data-options="iconCls:'icon-baocun'">确定</a>
						 <a id="cc_patientcancel" style="margin-left:40px" class="easyui-linkbutton" data-options="iconCls:'icon-chexiao'">取消</a>
					</div>
	
				</form>
			
		</div>
	</div>
</body>
</html>